package net.java.mediasystems.web;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public final class FileUploadUtil {
	private static final String MIME_TYPE_JPEG = "image/jpeg";
	private static final String MIME_TYPE_GIF = "image/gif";
	private static final String MIME_TYPE_BMP = "image/bmp";
	private static final String MIME_TYPE_SVG = "image/svg+xml";
	private static final String MIME_TYPE_TIFF = "image/tiff";
	
	private static final Map<String, String> MIME_TYPES = Collections.unmodifiableMap(new HashMap<String, String>() {
		
		private static final long serialVersionUID = -7743278370921086630L;
		
		{
			put("jpg", MIME_TYPE_JPEG);
			put("jpeg", MIME_TYPE_JPEG);
			put("jpe", MIME_TYPE_JPEG);
			put("gif", MIME_TYPE_GIF);
			put("bmp", MIME_TYPE_BMP);
			put("svg", MIME_TYPE_SVG);
			put("tif", MIME_TYPE_TIFF);
			put("tiff", MIME_TYPE_TIFF);
		}
	});
	
	private FileUploadUtil() {
		
	}
	
	public static String getMimeTypeForFile(String fileNameWithFileExtension) {
		String fileExtension = fileNameWithFileExtension.substring(fileNameWithFileExtension.lastIndexOf('.') + 1);
		return MIME_TYPES.get(fileExtension);
	}
}
